package com.xbts.web.controller.manager;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xbts.common.enums.EmailTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnEmailTemplate;
import com.xbts.system.service.ICnEmailTemplateService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;

/**
 * 邮件模板Controller
 * 
 * @author xbts
 * @date 2024-04-23
 */
@Api(tags = "邮件模板管理")
@RestController
@RequestMapping("/manager/email/template")
public class CnEmailTemplateController extends BaseController {

    @Autowired
    private ICnEmailTemplateService cnEmailTemplateService;

    /**
     * 查询邮件模板列表
     */
    @ApiOperation("获取邮件模板列表")
    @GetMapping("/list")
    public TableDataInfo list(CnEmailTemplate cnEmailTemplate) {
        startPage();
        List<CnEmailTemplate> list = cnEmailTemplateService.list();
        return getDataTable(list);
    }

    /**
     * 获取邮件模板详细信息
     */
    @ApiOperation("获取邮件模板详细")
    @ApiImplicitParam(name = "type", value = "邮件模板ID", required = true, dataTypeClass = EmailTypeEnum.class, paramType = "path")
    @GetMapping(value = "/{type}")
    public AjaxResult getInfo(@PathVariable("type") EmailTypeEnum typeEnum) {
        return success(cnEmailTemplateService.lambdaQuery().eq(CnEmailTemplate::getType, typeEnum.name()).one());
    }

    /**
     * 修改邮件模板
     */
    @ApiOperation("更新邮件模板")
    @Log(title = "邮件模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CnEmailTemplate cnEmailTemplate) {
        return toAjax(cnEmailTemplateService.updateById(cnEmailTemplate));
    }
}